// SPDX-FileCopyrightText: 2018-2020 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only

#define Timercmp(tvp, uvp, cmp) \
	(((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_usec cmp(uvp)->tv_usec) : ((tvp)->tv_sec cmp(uvp)->tv_sec))
#define Timeradd(tvp, uvp, vvp) \
	do { \
		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
		if ((vvp)->tv_usec >= 1000000) { \
			(vvp)->tv_sec++; \
			(vvp)->tv_usec -= 1000000; \
		} \
	} while (0)
#define Timersub(tvp, uvp, vvp) \
	do { \
		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
		if ((vvp)->tv_usec < 0) { \
			(vvp)->tv_sec--; \
			(vvp)->tv_usec += 1000000; \
		} \
	} while (0)
